
rem
bbdoc: Contains render code for entities.
about: A Renderable is not a component! A Renderable belongs to a 
TRenderFormComponent, and the render system runs this render method.
Images only. (for now)
endrem
Type TRenderable
	
	'components needed for drawing the renderable
	Field _position:TPositionComponent
	Field _transform:TTransformComponent
	Field _color:TColorComponent
	
	Field _image:TImage
	Field _frame:Int
		
	'entity will not be rendered when this is false.
	Field _visible:Int = True
	

	
	'image group is the group name in the resource manager
	'image name is the name of the image in that group
	'image frame is for using animimages.

	Function Create:TRenderable(w:TWorld, e:TEntity, imageLabel:String, imageGroup:String, imageFrame:Int = 0)
		Local r:TRenderable = New TRenderable
		
		'set mappers to essential components of this entity
		Local mapper:TComponentMapper = TComponentMapper.Create(New TTransformComponent, w)
		r._transform = TTransformComponent(mapper.Get(e))
		
		mapper:TComponentMapper = TComponentMapper.Create(New TPositionComponent, w)
		r._position = TPositionComponent(mapper.Get(e))
		
		mapper = TComponentMapper.Create(New TColorComponent, w)
		r._color = TColorComponent(mapper.Get(e))
		
		'set image and frame settings		
		r.SetImage(TResources.GetImage(imageLabel, imageGroup))
		r.SetFrame(imageFrame)
		Return r
	End Function

	
	Method Render()
		If _image = Null Return
		_color.Apply()
		_transform.Apply()
		DrawImage(_image, _position.GetRenderX(), _position.GetRenderY(), _frame)
	End Method
	
	
	Rem
	bbdoc: Sets visible flag.
	endrem
	Method SetVisible(bool:Int)
		_visible = bool
	End Method
	
	
	rem
	bbdoc: Retrieves visible flag.
	endrem
	Method GetVisible:Int()
		Return _visible
	End Method
	
	
	rem
	bbdoc: Returns the renderable image.
	endrem
	Method GetImage:TImage()
		Return _image
	End Method
	
	
	rem
	bbdoc: Sets the renderable image.
	endrem	
	Method SetImage(i:TImage)
		_image = i
	End Method

	
	rem
	bbdoc: Returns the current image frame.
	endrem	
	Method GetFrame:Int()
		Return _frame
	End Method
	
	
	rem
	bbdoc: Sets the image frame.
	endrem	
	Method SetFrame(f:Int)
		_frame = f
	End Method
	
	
	rem
	bbdoc: Returns positional component of this renderable.
	endrem	
	Method GetPosition:TPositionComponent()
		Return _position
	End Method
	
	
	rem
	bbdoc: Returns transform component of this renderable.
	endrem
	Method GetTransform:TTransformComponent()
		Return _transform
	End Method
	
	
	rem
	bbdoc: Returns color component of this renderable.
	endrem
	Method GetColor:TColorComponent()
		Return _color
	End Method
	
End Type